<?php
	header("Content-Type: text/html;charset=utf-8");
	include("function/_nosql.php"); //
	include("function/function.php");
	include("_include.user.judge.php");
	
	$kboy_user = $_SESSION['kboy_user'];
	$kboy_userid = $_SESSION['kboy_userid'];
	$action = chkstr(trim($_REQUEST['action']));
	$upload_img_code = chkstr(trim($_REQUEST['BaseImgCode']));
	
	if($action == "edit"){
		$new_file_name = date("YmdHis") . "_" . rand(10000, 99999) . "." . "png";
		$news_file_path = "UploadFile/image/".date("Ymd")."/";
		if(strlen($upload_img_code)>10){
			$base64_body = substr(strstr($upload_img_code,","),1);
			$data_code = base64_decode($base64_body);
			if(!is_dir($news_file_path)){
				mkdir($news_file_path);
			}
			$isUpload = file_put_contents($news_file_path.$new_file_name,$data_code);
			if($isUpload){
				// 修改数据
				$mysql = new sqlstr("kboy_user"); 
				$mysql -> set("user_face","/".$news_file_path.$new_file_name);
				$news_sql = $mysql -> updateSql("uid=$kboy_userid");
				$news_res = mysql_query($news_sql);
				if($news_res){
					echo "上传成功";
					exit();
				}else{
					echo "服务器内部错误";
					exit();
				}
			}else{
				echo "上传失败";
				exit();
			}
		}else{
			echo "参数错误";
			exit();
		}
	}else{
		echo erro("参数错误");
	}
?>